package com.appwoo.txtws.activity;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.ServerAppBean;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.bean.UserInfoBean;
import com.appwoo.txtws.component.FilterSoft;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.Logger;
import com.appwoo.txtws.component.RqSP;
import com.appwoo.txtws.service.UpdateService;
import com.appwoo.txtws.service.UserInfoService;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.xmlpull.v1.XmlPullParserException;

public class AboutTelephone extends AppActivity
{
  private static final String APK_PACKAGE_NAME = "com.appwoo.txtws.activity";
  private static final int DIALOG1 = 0;
  private static final int DIALOG_DOWNLOAD = 3;
  private static final int ERROR = -1;
  private Button btnCheckUpdate;
  private Bundle bundle = null;
  private UserInfoBean f_UserInfoBean = null;
  private ServerAppBean f_serverAppBean = null;
  private UpdateService f_updateService;
  private String f_url = "";
  private UserInfoService f_userInfoService = null;
  private boolean isCancelDownload = false;
  private TextView myProssBarhandleText;
  private String parientID = "";
  private ProgressBar progressBarHandle;
  String storegespace;
  String str1 = "/proc/meminfo";
  String str2 = "";
  private String strApkVersion = "";
  private TextView text_aboutus_version;
  private TextView text_bind_User;
  private TextView text_devicenum;
  private TextView text_memory;
  private TextView text_model;
  private TextView text_processor;
  private TextView text_storagespace;
  private TextView text_systemversion;
  private TextView text_version;
  private String updateStr = "";
  private ProgressDialog v_progressDialog = null;

  private String bg_checkUpdateVersion()
  {
    try
    {
      String str = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
      Log.v("verson", str);
      StateBean localStateBean = this.f_updateService.getUpdateUrl(str);
      this.f_url = localStateBean.getUrl();
      this.updateStr = localStateBean.getDesc();
      label54: return this.f_url;
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      break label54;
    }
    catch (IOException localIOException)
    {
      break label54;
    }
    catch (PackageManager.NameNotFoundException localNameNotFoundException)
    {
      break label54;
    }
  }

  private String bg_download()
  {
    Boolean localBoolean = Boolean.valueOf(isSDCard());
    String str = Environment.getExternalStorageDirectory().getPath() + "/download_cache";
    File localFile1 = new File(str);
    if (!localFile1.exists())
      localFile1.mkdir();
    HttpGet localHttpGet = new HttpGet(this.f_url);
    try
    {
      HttpResponse localHttpResponse = new DefaultHttpClient().execute(localHttpGet);
      if (localHttpResponse.getStatusLine().getStatusCode() != 200)
        break label299;
      InputStream localInputStream = localHttpResponse.getEntity().getContent();
      FileOutputStream localFileOutputStream;
      byte[] arrayOfByte;
      if (localBoolean.booleanValue())
      {
        localFileOutputStream = new FileOutputStream(str + "/txtw.apk");
        arrayOfByte = new byte[8192];
      }
      while (true)
      {
        int i = localInputStream.read(arrayOfByte);
        if (i == -1)
        {
          localFileOutputStream.close();
          localInputStream.close();
          if (!localBoolean.booleanValue())
            break label251;
          installApk(str + "/txtw.apk");
          return "";
          localFileOutputStream = openFileOutput("txtw.apk", 1);
          break;
        }
        localFileOutputStream.write(arrayOfByte, 0, i);
      }
    }
    catch (Exception localException)
    {
      return getString(2131427557);
    }
    label251: File localFile2 = getFilesDir();
    installApk(localFile2.getParent() + File.separator + localFile2.getName() + "/txtw.apk");
    label299: return "";
  }

  private Dialog buildDialog(Context paramContext)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
    localBuilder.setIcon(2130837508);
    localBuilder.setTitle(getResources().getString(2131427429));
    localBuilder.setMessage(formString());
    localBuilder.setPositiveButton(getString(2131427513), new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        new AboutTelephone.DownloadAsyncTask(AboutTelephone.this).execute(new Void[] { null });
      }
    });
    localBuilder.setNegativeButton(getString(2131427512), null);
    localBuilder.setCancelable(false);
    return localBuilder.create();
  }

  private void createOrShowDialog()
  {
    if ((this.v_progressDialog == null) || (!this.v_progressDialog.isShowing()))
    {
      this.v_progressDialog = new ProgressDialog(this);
      this.v_progressDialog.setMessage(getString(2131427561));
      this.v_progressDialog.setCancelable(false);
      this.v_progressDialog.show();
    }
  }

  private Dialog downDialog(Context paramContext)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
    localBuilder.setTitle(getString(2131427559));
    View localView = getLayoutInflater().inflate(2130903084, null);
    localBuilder.setView(localView);
    this.progressBarHandle = ((ProgressBar)localView.findViewById(2131493072));
    this.myProssBarhandleText = ((TextView)localView.findViewById(2131493073));
    localBuilder.setOnCancelListener(new DialogInterface.OnCancelListener()
    {
      public void onCancel(DialogInterface paramAnonymousDialogInterface)
      {
        AboutTelephone.this.isCancelDownload = true;
      }
    });
    localBuilder.setNegativeButton(getString(2131427560), new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        AboutTelephone.this.isCancelDownload = true;
      }
    });
    return localBuilder.create();
  }

  public static boolean externalMemoryAvailable()
  {
    return Environment.getExternalStorageState().equals("mounted");
  }

  private String formString()
  {
    Object localObject = "";
    try
    {
      localObject = localObject + getResources().getString(2131427438) + "\n";
      String[] arrayOfString = this.updateStr.split("#");
      for (int i = 0; ; i++)
      {
        if (i >= arrayOfString.length)
          return localObject;
        String str = localObject + (i + 1) + "、" + arrayOfString[i] + "\n";
        localObject = str;
      }
    }
    catch (NullPointerException localNullPointerException)
    {
      Logger.e("xjf", localNullPointerException.toString());
      return localObject;
    }
    catch (Exception localException)
    {
      Logger.e("xjf", localException.toString());
    }
    return localObject;
  }

  public static String formatSize(long paramLong)
  {
    boolean bool = paramLong < 1024L;
    String str = null;
    if (!bool)
    {
      str = "KiB";
      paramLong /= 1024L;
      if (paramLong >= 1024L)
      {
        str = "MB";
        paramLong /= 1024L;
      }
      if (paramLong >= 1024L)
      {
        str = "G";
        paramLong /= 1024L;
      }
    }
    StringBuilder localStringBuilder = new StringBuilder(Long.toString(paramLong));
    for (int i = -3 + localStringBuilder.length(); ; i -= 3)
    {
      if (i <= 0)
      {
        if (str != null)
          localStringBuilder.append(str);
        return localStringBuilder.toString();
      }
      localStringBuilder.insert(i, ',');
    }
  }

  private String getApkVersion()
  {
    try
    {
      String str = getPackageManager().getPackageInfo("com.appwoo.txtws.activity", 0).versionName;
      return str;
    }
    catch (PackageManager.NameNotFoundException localNameNotFoundException)
    {
      localNameNotFoundException.printStackTrace();
    }
    return "";
  }

  public static long getAvailableInternalMemorySize()
  {
    StatFs localStatFs = new StatFs(Environment.getDataDirectory().getPath());
    return localStatFs.getBlockSize() * localStatFs.getAvailableBlocks();
  }

  public static String getCpuName()
  {
    try
    {
      String[] arrayOfString = new BufferedReader(new FileReader("/proc/cpuinfo")).readLine().split(":\\s+", 2);
      for (int i = 0; ; i++)
        if (i >= arrayOfString.length)
        {
          String str = arrayOfString[1];
          return str;
        }
    }
    catch (FileNotFoundException localFileNotFoundException)
    {
      localFileNotFoundException.printStackTrace();
      return null;
    }
    catch (IOException localIOException)
    {
      while (true)
        localIOException.printStackTrace();
    }
  }

  public static long getTotalExternalMemorySize()
  {
    if (externalMemoryAvailable())
    {
      StatFs localStatFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
      return localStatFs.getBlockSize() * localStatFs.getBlockCount();
    }
    return -1L;
  }

  private void initActionBar()
  {
    hideBarHome();
    if (!FilterSoft.IsCustomVersion())
      setBarTitle(getResources().getString(2131427425));
    while (true)
    {
      setBarBackOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramAnonymousView)
        {
          AboutTelephone.this.finish();
        }
      });
      return;
      setBarTitle(getResources().getString(2131428086));
    }
  }

  private void installApk(String paramString)
  {
    File localFile = new File(paramString);
    Intent localIntent = new Intent();
    localIntent.addFlags(268435456);
    localIntent.setAction("android.intent.action.VIEW");
    localIntent.setDataAndType(Uri.fromFile(localFile), "application/vnd.android.package-archive");
    startActivity(localIntent);
  }

  private void post_checkUpdateVersion(String paramString)
  {
    if ((paramString == null) || (paramString.equals("")))
    {
      alertMessage(getString(2131427558));
      return;
    }
    if (!isSDCard())
    {
      if (Global.getMemorySize() >= 30)
      {
        showDialog(0);
        return;
      }
      alertMessage(getString(2131427337));
      return;
    }
    showDialog(0);
  }

  private void post_download(String paramString)
  {
    if ((paramString != null) && (!paramString.equals("")))
      alertMessage(paramString);
  }

  private void showView()
  {
    new Flash_AsyncTask().execute(new String[] { "check" });
  }

  protected void backKeyCallBack()
  {
    finish();
  }

  public long[] getRomMemroy()
  {
    long[] arrayOfLong = new long[2];
    arrayOfLong[0] = getTotalInternalMemorySize();
    StatFs localStatFs = new StatFs(Environment.getDataDirectory().getPath());
    arrayOfLong[1] = (localStatFs.getBlockSize() * localStatFs.getAvailableBlocks());
    return arrayOfLong;
  }

  public long getTotalInternalMemorySize()
  {
    StatFs localStatFs = new StatFs(Environment.getDataDirectory().getPath());
    return localStatFs.getBlockSize() * localStatFs.getBlockCount();
  }

  public boolean isSDCard()
  {
    try
    {
      long l = new Date().getTime();
      File localFile = new File("/sdcard/" + l + ".test");
      boolean bool = localFile.createNewFile();
      localFile.delete();
      Logger.i("xjf", "sdcard can use");
      return bool;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      Logger.i("xjf", "No SDCard!!");
    }
    return false;
  }

  public void onBackPressed()
  {
    finish();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903040);
    initActionBar();
    this.btnCheckUpdate = ((Button)findViewById(2131492867));
    this.text_devicenum = ((TextView)findViewById(2131492865));
    this.text_model = ((TextView)findViewById(2131492869));
    this.text_version = ((TextView)findViewById(2131492870));
    this.text_systemversion = ((TextView)findViewById(2131492871));
    this.text_processor = ((TextView)findViewById(2131492872));
    this.text_memory = ((TextView)findViewById(2131492873));
    this.text_storagespace = ((TextView)findViewById(2131492874));
    this.text_bind_User = ((TextView)findViewById(2131492868));
    this.text_aboutus_version = ((TextView)findViewById(2131492866));
    this.strApkVersion = getApkVersion();
    this.text_aboutus_version.setText(this.strApkVersion);
    this.f_serverAppBean = ((ServerAppBean)getApplication());
    this.bundle = new Bundle();
    this.f_updateService = new UpdateService();
    this.f_userInfoService = new UserInfoService();
    String str3 = Global.getIMEI(this);
    this.text_devicenum.setText(str3);
    this.text_model.setText(Build.MODEL);
    this.text_version.setText(Build.DISPLAY);
    this.text_systemversion.setText(Build.VERSION.RELEASE);
    this.btnCheckUpdate.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        if (!AboutTelephone.this.isNetworkAvailable(AboutTelephone.this))
        {
          AboutTelephone.this.alertMessage(AboutTelephone.this.getString(2131428051));
          return;
        }
        AboutTelephone.this.showView();
      }
    });
    String str4 = formatSize(getAvailableInternalMemorySize());
    this.text_memory.setText(str4);
    long l = getTotalExternalMemorySize();
    if (l != -1L);
    for (this.storegespace = formatSize(l); ; this.storegespace = formatSize(getTotalInternalMemorySize()))
    {
      this.text_storagespace.setText(this.storegespace);
      this.text_processor.setText(getCpuName());
      this.parientID = new RqSP().getParentId(this);
      this.text_bind_User.setText(this.parientID);
      return;
    }
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    case 1:
    case 2:
    default:
      return null;
    case 0:
      return buildDialog(this);
    case 3:
    }
    return downDialog(this);
  }

  class DownloadAsyncTask extends AsyncTask<Void, Integer, Integer>
  {
    private final String downPath = Environment.getExternalStorageDirectory().getPath() + "/download_cache";
    private int fileSize;
    private String filename;
    private FileOutputStream fos;
    private InputStream is;

    DownloadAsyncTask()
    {
    }

    protected Integer doInBackground(Void[] paramArrayOfVoid)
    {
      this.filename = AboutTelephone.this.f_url.substring(1 + AboutTelephone.this.f_url.lastIndexOf("/"));
      try
      {
        URL localURL = new URL(AboutTelephone.this.f_url);
        Logger.e("xjf", "downpath: " + this.downPath);
        URLConnection localURLConnection = localURL.openConnection();
        localURLConnection.connect();
        this.is = localURLConnection.getInputStream();
        this.fileSize = localURLConnection.getContentLength();
        AboutTelephone.this.progressBarHandle.setMax(this.fileSize);
        if (this.fileSize <= 0)
          throw new RuntimeException(AboutTelephone.this.getString(2131427562));
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        Logger.d("xjf", localException.getMessage());
        return Integer.valueOf(this.fileSize);
        if (this.is == null)
          throw new RuntimeException("stream is null");
      }
      finally
      {
        AboutTelephone.this.isCancelDownload = false;
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
      }
      label272: byte[] arrayOfByte;
      int i;
      label306: int j;
      if (AboutTelephone.this.isSDCard())
      {
        this.fos = new FileOutputStream(this.downPath + "/" + this.filename);
        arrayOfByte = new byte[1024];
        i = 0;
        Logger.d("xjf", "fileSize:" + this.fileSize);
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(0);
        j = this.is.read(arrayOfByte);
        if (j != -1)
          break label367;
      }
      while (true)
      {
        AboutTelephone.this.isCancelDownload = false;
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
        break;
        this.fos = AboutTelephone.this.openFileOutput(this.filename, 1);
        break label272;
        label367: this.fos.write(arrayOfByte, 0, j);
        i += j;
        Integer[] arrayOfInteger = new Integer[1];
        arrayOfInteger[0] = Integer.valueOf(i);
        publishProgress(arrayOfInteger);
        if (AboutTelephone.this.isCancelDownload)
          this.fileSize = -1;
        boolean bool = AboutTelephone.this.isCancelDownload;
        if (!bool)
          break label306;
      }
    }

    protected void onPostExecute(Integer paramInteger)
    {
      if (paramInteger.intValue() != -1)
        Toast.makeText(AboutTelephone.this, AboutTelephone.this.getString(2131427563) + Math.round(100.0F * paramInteger.intValue() / 1048576.0F) / 100.0F + "MB", 1).show();
      try
      {
        while (true)
        {
          AboutTelephone.this.dismissDialog(3);
          try
          {
            label75: Boolean localBoolean = Boolean.valueOf(AboutTelephone.this.isSDCard());
            if (paramInteger.intValue() != -1)
            {
              SharedPreferences.Editor localEditor = AboutTelephone.this.getSharedPreferences("sys", 0).edit();
              localEditor.putInt("isupload", 1);
              localEditor.commit();
              if (!localBoolean.booleanValue())
                break label225;
              if (paramInteger.intValue() != -1)
                AboutTelephone.this.installApk(this.downPath + "/" + this.filename);
            }
            while (true)
            {
              if (this.is != null)
                this.is.close();
              if (this.fos != null)
                this.fos.close();
              return;
              this.fos = null;
              this.is = null;
              break;
              label225: File localFile = AboutTelephone.this.getFilesDir();
              if (paramInteger.intValue() != -1)
                AboutTelephone.this.installApk(localFile.getParent() + File.separator + localFile.getName() + "/" + this.filename);
            }
          }
          catch (Exception localException2)
          {
            Logger.e("xjf", "error: " + localException2.getMessage(), localException2);
            return;
          }
        }
      }
      catch (Exception localException1)
      {
        break label75;
      }
    }

    protected void onPreExecute()
    {
      File localFile = new File(this.downPath);
      if (!localFile.exists())
        localFile.mkdir();
      AboutTelephone.this.showDialog(3);
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
      AboutTelephone.this.progressBarHandle.setProgress(paramArrayOfInteger[0].intValue());
      int i = (int)(100.0F * (AboutTelephone.this.progressBarHandle.getProgress() / AboutTelephone.this.progressBarHandle.getMax()));
      AboutTelephone.this.myProssBarhandleText.setText(i + "%");
    }
  }

  public class Flash_AsyncTask extends AsyncTask<String, Integer, String>
  {
    private String method = "";

    public Flash_AsyncTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.method = paramArrayOfString[0];
      if (this.method.equals("check"))
        return AboutTelephone.this.bg_checkUpdateVersion();
      if (this.method.equals("download"))
        return AboutTelephone.this.bg_download();
      return "";
    }

    protected void onPostExecute(String paramString)
    {
      if (this.method.equals("check"))
        AboutTelephone.this.post_checkUpdateVersion(paramString);
      try
      {
        while (true)
        {
          AboutTelephone.this.v_progressDialog.dismiss();
          return;
          if (this.method.equals("download"))
            AboutTelephone.this.post_download(paramString);
        }
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
      }
    }

    protected void onPreExecute()
    {
      AboutTelephone.this.createOrShowDialog();
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.AboutTelephone
 * JD-Core Version:    0.6.2
 */